package com.servlet.project.service;

import com.servlet.project.entity.Activity;
import com.servlet.project.entity.Trainingrecord;
import com.servlet.project.util.JdbcUtil;

import java.util.List;

public class TrainingrecordService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into trainingrecord(memberid,membername,trainingid,trainingcontent,trainingdate,recordinfo) values(?,?,?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Trainingrecord> getListAll(int page, int rows, Trainingrecord obj) {
        String sql="select * from trainingrecord where 1=1 ";
        if(obj.getMembername()!=null&&!obj.getMembername().equals("")){
            sql+=" and membername like '%"+obj.getMembername()+"%' ";
        }
        if(obj.getMemberid()!=0){
            sql+=" and memberid='"+obj.getMemberid()+"' ";
        }
        sql+=" limit "+page+","+rows;
        List<Trainingrecord> memberList= JdbcUtil.executeQuery(sql,null,Trainingrecord.class);
        return memberList;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Trainingrecord obj) {
        String sql="select * from trainingrecord where 1=1 ";
        if(obj.getMembername()!=null&&!obj.getMembername().equals("")){
            sql+=" and membername like '%"+obj.getMembername()+"%' ";
        }
        if(obj.getMemberid()!=0){
            sql+=" and memberid='"+obj.getMemberid()+"' ";
        }
        List<Trainingrecord> memberList= JdbcUtil.executeQuery(sql,null,Trainingrecord.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update trainingrecord set recordinfo=? where recordid=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param recordid
     * @return
     */
    public Trainingrecord getId(String recordid) {
        String sql="select * from trainingrecord where recordid="+recordid;
        List<Trainingrecord> users= JdbcUtil.executeQuery(sql,null,Trainingrecord.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from trainingrecord  where recordid=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
